package com.cb.myzhxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cb.myzhxy.mapper.ClazzMapper;
import com.cb.myzhxy.pojo.Clazz;
import com.cb.myzhxy.service.ClazzService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
*
*/
@Service("clazzServiceImpl")
@Transactional
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {

    @Override
    public IPage<Clazz> getClazzsByOpr(Page<Clazz> page, Clazz clazz) {
        LambdaQueryWrapper<Clazz> queryWrapper = new LambdaQueryWrapper<>();
        if(clazz!=null){
            //年级名称条件
            String gradeName = clazz.getGradeName();
            if(!StringUtils.isEmpty(gradeName)){
                queryWrapper.eq(Clazz::getGradeName,gradeName);
            }
            //班级名称条件
            String name = clazz.getName();
            if(!StringUtils.isEmpty(name)){
                queryWrapper.like(Clazz::getName,name);
            }
            queryWrapper.orderByDesc(Clazz::getId);
            queryWrapper.orderByAsc(Clazz::getName);
        }
        Page<Clazz> page1 = baseMapper.selectPage(page, queryWrapper);
        return page1;
    }

    @Override
    public List<Clazz> getClazzs() {
        List<Clazz> clazzes = baseMapper.selectList(null);
        return clazzes;
    }
}
